package com.xrit.sunnyday.service.impl;

import com.alibaba.dubbo.common.utils.StringUtils;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xrit.sunnyday.dao.RoleMapper;
import com.xrit.sunnyday.pojo.Role;
import com.xrit.sunnyday.service.RoleService;
import com.xrit.sunnyday.common.PageResult;
import com.xrit.sunnyday.common.QueryPageBean;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service(interfaceClass = RoleService.class)
public class RoleServiceImpl implements RoleService {
    @Autowired
    private RoleMapper roleMapper;
    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        //判断是否有条件
        if(!(StringUtils.isEmpty(queryPageBean.getQueryString()))){
            queryPageBean.setQueryString("%"+queryPageBean.getQueryString()+"%");
        }
        //开启分页插件
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        //调用查询方法
        List<Role> roleList = roleMapper.findPage(queryPageBean.getQueryString());
        //放入pageinfo中
        PageInfo<Role> pageInfo = new PageInfo<>(roleList);
        return new PageResult(pageInfo.getTotal(),pageInfo.getList());
    }
}
